﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using PClusterModel.Comparer;

namespace PClusterModel.Utils
{
    public static class Utilities
    {
        public static int GetNumberOfSetBitsForBitmap(BitArray bitmap)
        {
            int hash = Comparer.BitarrayEqualityComparer.Instance.GetHashCode(bitmap);
            return GetNumberOfSetBits(hash);
        }

        public static int GetNumberOfSetBits(int hash)
        {
            int count = 0;
            while (hash != 0)
            {
                count++;
                hash &= (hash - 1);
            }
            return count;
        }

        public static bool IsBitmapSubsetOfSecondBitmap(BitArray subSet, BitArray superSet)
        {
            int hashOfSubset = BitarrayEqualityComparer.Instance.GetHashCode(subSet);
            int hashOfSuperset = BitarrayEqualityComparer.Instance.GetHashCode(superSet);

            int result = hashOfSubset & hashOfSuperset;

            return result == hashOfSubset;
        }

    }
}
